package com.devilvan.betrice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.dto.SysUserDto;
import com.devilvan.betrice.po.SysUserPo;
import com.devilvan.betrice.service.SysUserService;
import com.devilvan.betrice.mapper.SysUserMapper;
import com.devilvan.betrice.repository.SysUserRepository;
import org.springframework.stereotype.Service;
import com.devilvan.betrice.util.UCopy;

import javax.annotation.Resource;
import java.util.List;

/**
* @author Evad.Wu
* @Description 用户信息表 业务逻辑类
* @date 2023-08-14
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserPo> implements SysUserService {
    @Resource(name = "sysUserRepository")
    private SysUserRepository sysUserRepository;

    @Override
    public SysUserPo saveUpdate(SysUserDto sysUserDto) {
        SysUserPo sysUserPo = new SysUserPo();
        UCopy.fullCopy(sysUserDto, sysUserPo);
        return sysUserRepository.saveAndFlush(sysUserPo);
    }

    @Override
    public List<SysUserPo> saveUpdateBatch(List<SysUserDto> list) {
        List<SysUserPo> sysUserPoList = UCopy.fullCopyCollections(list, SysUserPo.class);
        return sysUserRepository.saveAllAndFlush(sysUserPoList);
    }

    @Override
    public SysUserPo loadUserByUsername(String username) {
        return sysUserRepository.loadByUserName(username);
    }
}
